package cn.jingyuan.fox.user.support.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.Thread.UncaughtExceptionHandler;

/**
 * simple uncaught exception handler
 *
 * @author Liu Kefeng
 * @since 2020/9/15
 */
public class SimpleUncaughtExceptionHandler implements UncaughtExceptionHandler {

    protected Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        long id = t.getId();
        String name = t.getName();
        ThreadGroup threadGroup = t.getThreadGroup();
        String threadGroupName = null;
        if (null != threadGroup) {
            threadGroupName = threadGroup.getName();
        }

        log.warn("happens uncaught exception in thread id={} , name={} , threadGroup={}", id, name, threadGroupName, e);
    }

}

